package cn.snowheart

/**
 * 特征，等价于Java中的interface
 *
 * @author liuwanxiang
 * @version 2019/05/31
 */
class TraitExample {

    static void main(String[] args) {
        // Bird 对象
        def bird = new Bird()
        bird.fly()

        // Airplane 对象
        def plane = new Boeing()
        plane.fly()
        plane.stop()
        plane = new Airbus()
        plane.fly()
        plane.stop()

    }

}

trait Flyable {
    abstract void fly()
}

interface Airplane extends Flyable {
    void stop()
}

class Bird implements Flyable {

    @Override
    void fly() {
        println "I'm a bird, I can fly~"
    }

}

class Boeing implements Airplane {
    @Override
    void fly() {
        println "Boeing airplane flying~"
    }

    @Override
    void stop() {
        println "Boeing stop"
    }
}

class Airbus implements Airplane {

    @Override
    void fly() {
        println "Airbus airplane flying~"
    }

    @Override
    void stop() {
        println "Airbus stop"
    }
}